package org.ccf.certified.bean;

/**
 * @author LiuFang
 * @date 2022/1/12
 */
public class ResponseBean {

    /** 封装基础的结果响应参数 */
    private static int codeSuccessCode = 200;
    private static int codeFailCode = 500;
    private static String codeSuccessMsg = "SUCCESS";
    private static String codeFailMsg = "Fail";

    // http 状态码
    private int code;

    // 返回信息
    private String msg;

    // 返回的数据
    private Object data;

    public ResponseBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    /**
     * 基础返回对象
     * @param code HTTP响应吗
     * @param msg   响应信息
     * @param data  响应数据
     * @return  ResponseBean Object
     */
    public static ResponseBean getResults(int code, String msg, Object data){
        return new ResponseBean(code, msg, data);
    }

    /**
     * 数据操作成功(无结果)
     * @return  ResponseBean Object
     */
    public static ResponseBean getResultsSuccess(){
        return new ResponseBean(ResponseBean.codeSuccessCode, ResponseBean.codeSuccessMsg,null);
    }

    /**
     * 数据操作成功(有结果)
     * @param data 返回的结果对象
     * @return  ResponseBean Object
     */
    public static ResponseBean getResultsSuccess(Object data){
        return new ResponseBean(ResponseBean.codeSuccessCode, ResponseBean.codeSuccessMsg, data);
    }

    /**
     * 数据操作失败(无结果)
     * @return  ResponseBean Object
     */
    public static ResponseBean getResultsFail(){
        return new ResponseBean(ResponseBean.codeFailCode, ResponseBean.codeFailMsg,null);
    }

    /**
     * 数据操作失败(有结果)
     * @param data 返回的结果对象
     * @return  ResponseBean Object
     */
    public static ResponseBean getResultsFail(Object data){
        return new ResponseBean(ResponseBean.codeFailCode, ResponseBean.codeFailMsg, data);
    }
}
